package stack

type Stack struct {
	Element []interface{}
}

func NewStack() *Stack {
	return &Stack{}
}

func (stack *Stack) Push(value ...interface{}) {
	stack.Element = append(stack.Element, value...)
}

//Stack的size
func (stack *Stack) Size() int {
	return len(stack.Element)
}

func (s *Stack) IsEmpty() bool {
	return len(s.Element) == 0
}

func (stack *Stack) Top() (value interface{}) {
	if stack.Size() > 0 {
		return stack.Element[stack.Size()-1]
	}
	return nil
}

func (stack *Stack) Pop() (interface{}, bool) {
	if stack.IsEmpty() {
		return "", false
	} else {
		index := len(stack.Element) - 1       // Get the index of the top most element.
		element := (stack.Element)[index]     // Index into the slice and obtain the element.
		stack.Element = stack.Element[:index] // Remove it from the stack by slicing it off.
		return element, true
	}
}
